package com.changgou.goods.dao;

import com.changgou.goods.pojo.Spec;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import tk.mybatis.mapper.common.Mapper;

import java.util.List;

public interface SpecMapper extends Mapper<Spec> {
    @Select("SELECT NAME FROM tb_spec")
    List<String> fedAll();

    /**
     * 根据模板id删除spec
     * @param id
     */
    @Delete("delete from tb_spec where template_id = #{id}")
    void deleteByTemplateId(Integer id);

    //根据ID获取规格总记录数
    @Select("SELECT " +
            " count(*) " +
            " FROM " +
            " tb_template t,tb_spec s " +
            " WHERE " +
            " s.`template_id` = #{id} AND s.`template_id` = t.id")
    Long findCountById( int id);

    //根据ID对规格表进行分页查询
    @Select("SELECT " +
            " s.`id`,s.`name`,s.`options`,s.`seq` ,t.`name` template_name " +
            " FROM " +
            " tb_template t,tb_spec s " +
            " WHERE " +
            " s.`template_id` = #{id} AND s.`template_id` = t.id " +
            " limit #{start} , #{size}")
    List<Spec> findPageById(@Param("id") int id, @Param("start") int start, @Param("size") int size);



}
